<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<%@ page contentType="text/html; charset=UTF-8" language="java"
	import="java.util.*" pageEncoding="UTF-8"%>
<%@ include file="/page/base.jsp"%>
<%@ taglib prefix="d" uri="/doone-comm-ui-tags"%>

<html>
	<head>
		<title>详情信息管理</title>
		<meta http-equiv="pragma" content="no-cache">
		<meta http-equiv="cache-control" content="no-cache">
		<meta http-equiv="expires" content="0">
		<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
		<meta http-equiv="description" content="This is my page">
		<!--
	<link rel="stylesheet" type="text/css" href="styles.css">
	-->
		<link type="text/css" href="../manage/css/layout.css" rel="stylesheet" />
		<link type="text/css" href="../manage/css/new_style.css"
			rel="stylesheet" />
		<link rel="stylesheet" type="text/css"
			href="<%=path%>/manage/css/zTreeStyle.css" />
		<link rel="stylesheet" type="text/css"
			href="<%=path%>/manage/css/colorbox.css" />
		<script type="text/javascript"
			src="<%=path%>/manage/js/jquery-1.4.4.min.js"></script>

		<script type="text/javascript"
			src="<%=path%>/manage/js/easyTooltip.js"></script>
		<script type="text/javascript"
			src="<%=path%>/manage/js/jquery-ui-1.8.11.custom.min.js"></script>
		<script type="text/javascript"
			src="<%=path%>/manage/js/jquery.wysiwyg.js"></script>
		<script type="text/javascript"
			src="<%=path%>/manage/js/hoverIntent.js"></script>
		<script type="text/javascript" src="<%=path%>/manage/js/superfish.js"></script>
		<script type="text/javascript" src="<%=path%>/manage/js/custom.js"></script>
		<script type="text/javascript"
			src="<%=path%>/manage/js/My97DatePicker/WdatePicker.js"></script>
		<script type="text/javascript"
			src="<%=path%>/manage/js/jquery.ztree.core-3.1.js"></script>
		<script type="text/javascript"
			src="<%=path%>/manage/js/jquery.colorbox-min.js"></script>
		<script type="text/javascript"
			src="<%=path%>/manage/js/jquery_form.js"></script>
		<style type="text/css">
			.uploadarea {margin:10px 5px auto auto;}
			#excelImpForm span {color:#555;}
			#helpTip {
				display:block;
				font-family:Tahoma, Verdana, Arial, sans-serif;
				font-size:10px;
				padding:9px;
				border:1px solid #bae2f0;
				background:#e3f4f9;	
				margin:auto auto .5em 0;
			}		
			fieldset label{
				
			}
		</style>
	</head>
	<script type="text/javascript">
	  
	 function delContentDetail(intContentId,intCateId){
	 	if (confirm("慎重考虑是否确定删除该记录?删除后无法查看该条记录！！！")) {
	 		showLoadStatus();
	 		//检测内容是否被绑定
	 		$.get(root + '/dataBinding/checkIfContentIsBinded.action',{'intContentId' : intContentId},function(data){
	 			if(data=="true"){
	 				if(confirm("该条记录已经被页面绑定，删除将会解绑，是否继续删除？")){
	 					deleteContent(intContentId,intCateId,"true");
	 				} else {
	 					hideLoadStatus();
	 				}
	 			} else {
	 				deleteContent(intContentId,intCateId,"false");
	 			}
	 		});
		}
	}
	
	function deleteContent(intContentId,intCateId,isBinded) {
		$.ajax({
			url : root + '/dataBinding/goDelContentDetail.action',
			method : 'post',
			data : {
				'intContentId' : intContentId,
				'isBinded' : isBinded
			},
			success : function(data) {
				window.location.href = root
						+ '/dataBinding/getAppContent.action?intCateId='+intCateId;
				hideLoadStatus();
			},
			error : function(err) {
				if (err.responseText != '')
					alert(err.responseText);
				else
					alert("请求失败！");
			}
		});
	}
	  
	//应用内容管理模块树加载	
	var setting1 = {
		view: {
			dblClickExpand: false,
			showLine: true,
			selectedMulti: false,
			expandSpeed: ($.browser.msie && parseInt($.browser.version)<=6)?"":"fast"
		},		
		//异步加载
		async: {
		enable: true,
		type:"post",
		url: "<%=path%>/dataBinding/getAppCatlogTree.action",
		autoParam: ["id"]
	    },
		data: {
			simpleData: {
				enable:true,
				idKey: "id",
				pIdKey: "pId",
				rootPId: ""
			}
		},
		callback: {
			beforeClick: function(treeId, treeNode) {
			
				var zTree = $.fn.zTree.getZTreeObj("tree");
				if (treeNode.isParent) {
					zTree.expandNode(treeNode);
					//demoIframe.attr("src",'<%=path%>/dataBinding/getAppCatelogById.action?id='+treeNode.id);
					//demoIframe.attr("target","content");
					return true;
				} else {
				    //叶子节点不处理
					demoIframe.attr("src",'<%=path%>/dataBinding/goCopyContent.action?intCateId='+ treeNode.id);
					demoIframe.attr("target", "content");
					return true;
				}
			}
		}
	};

	var zNodes;
	$(document).ready(function() {
		//应用内容管理
		var t = $("#tree");
		t = $.fn.zTree.init(t, setting1, zNodes);
		demoIframe = $("#content");
		demoIframe.bind("load", loadReady);
		var zTree = $.fn.zTree.getZTreeObj("tree");
		zTree.selectNode(zTree.getNodeByParam("id", 0));

		//加载dialog
		$("#addContentDialog").dialog({
			autoOpen : false,
			width : 1000,
			height : 450,
			modal : true,
			title : '新增已有详情',
			buttons : {
				"保存" : function() {
					sumitBtn();
					$(this).dialog("close");
				},
				"取消" : function() {
					$(this).dialog("close");
					$("#copyContetnForm")[0].reset();
				}
			},
			close : function() {
				$("#copyContetnForm")[0].reset();
			}
		});

		$(".inline").colorbox({
			width:"500px", 
			height:"340px",
			title:"在您选择的分类下导入excel表的详情",
			top:"150px", 
			inline:true,
			overlayClose:false,
			onOpen:function(){
				$("#uploadArea").html("<input type=\"file\" name=\"fileInput\" value=\"\" id=\"excelImpForm_fileInput\">");
				$("#infoShow").html("");
			},
			onClosed:function() {
				if(($("#infoShow").html()).indexOf("导入成功") >= 0) {
					refreshData($("#excelImpForm_intCateId").val());
				}
			}
		});
	});
	function sumitBtn() {
		//$("iframe").contents().find("#contengCks").val();
		//alert($("#contengCks").val());	
		contentCked = $("iframe").contents().find("#contengCks").val();
		$("#contengCks").attr("value", contentCked);
		$("#copyContetnForm").submit();
	}

	function loadReady() {
		var bodyH = demoIframe.contents().find("body").get(0).scrollHeight, htmlH = demoIframe
				.contents().find("html").get(0).scrollHeight, maxH = Math.max(
				bodyH, htmlH), minH = Math.min(bodyH, htmlH), h = demoIframe
				.height() >= maxH ? minH : maxH;
		if (h < 530)
			h = 530;
		demoIframe.height(h);
	}
	//点击节点在右侧显示详细信息
	function zTreeOnClick(event, treeId, treeNode) {
		id = treeNode.id;
		selectNode = treeNode;
		treeNodeReload();
		zTree.expandNode(treeNode, true);
		if (pageFlag) {
			//重置链接地址
			document.frames("content").refreshHref(id);
			//刷新DataGrid
			document.frames("content").refreshDataGrid(id);
		} else {
			document.frames("content").history.back();
			pageFlag = true;
		}
	}

	function loadTree() {
		//更改css樣式
		$("#div_tab").attr("class", "tab_div1");
		var t = $("#tree");
		t = $.fn.zTree.init(t, setting, zNodes);
		demoIframe = $("#content");
		demoIframe.bind("load", loadReady);
		var zTree = $.fn.zTree.getZTreeObj("tree");
		zTree.selectNode(zTree.getNodeByParam("id", 0));

	}

	//open dialog
	function openDialog() {
		$("#addContentDialog").dialog("open");
	}
	
	//查看与内容相关的地理位置信息
	function getEnterShop(intContentId) {
		window.location.href = root + '/enterShop/getEnterShopinfo.action?contentId='+intContentId;
	}
	
	function refreshData(intCateId) {
		window.location.href = root + '/dataBinding/getAppContent.action?intCateId='+intCateId;
	}
	
	function excelImp() {
		var errInfo = checkInputOption();
		if(errInfo != ""){
			$("#infoShow").html(errInfo);
			return;
		}		
		var options = {success:function(responseText, statusText){
			if(responseText.indexOf("导入成功")>=0) {
				$("#uploadArea").html("<input type=\"file\" name=\"fileInput\" value=\"\" id=\"excelImpForm_fileInput\">");
			}
			$("#infoShow").html(responseText);
			document.getElementById("cboxLoadedContent").scrollTop = document.getElementById("colorbox").scrollHeight;
			$("#excelImpBtn").attr("disabled",false);
		}};
		$("#excelImpForm").ajaxSubmit(options);
		var loading = "<img src='"+root+"/manage/images/loading.gif'>";
		$("#infoShow").html(loading+"  导入中，请勿关闭窗口...");
		$("#excelImpBtn").attr("disabled",true);
	}
	
	function checkInputOption() {
		var reg = new RegExp("^[0-9]*$");
		var errMsg = "";
		var sheetNo = $("#excelImpForm_sheetNo").val();
		var headRow = $("#excelImpForm_headRow").val();
		if (sheetNo != "" && !reg.test(sheetNo)){
			errMsg="excel sheet no必须为数字,";
		}
		if (headRow != "" && !reg.test(headRow)){
			errMsg +="excel表头行数必须为数字";
		}
		return errMsg.substring(0, errMsg.length - 1);
	}
</script>
	<body>
		<div>
			<p class="sitemap">
				当前位置：分类管理 > 详情信息管理
			</p>
			<h1>
				详情信息管理
			</h1>
			<div>
				<!-- Tabs -->
				<div id="tabs">
					<ul>
						<li>
							<a href="#tabs-1">详情信息列表</a>
						</li>

					</ul>

					<div>
						<a class="btn_addnew" onclick="showLoadStatus();"
							href="<%=path%>/dataBinding/goAddContent.action?intCateId=<s:property value="intCateId"/>">添加详情</a>
						<%-- 
						<a class="btn_excel inline"
							href="#inline_content">excel导入</a>
						--%>
						<div style='display:none'>
							<div id='inline_content' style='padding:10px; background:#fff;'>
							<s:form action="/excel/impConsFromExcel.action" name="excelImpForm"
								id="excelImpForm" enctype="multipart/form-data" method="post">
								<s:hidden name="intCateId"></s:hidden>
								<div id="helpTip">
									<span>Tip:多次导入相同excel会重复添加记录；如果要导入用户信息请指定excel中的哪一列作为用于手机端登录的唯一标识；如果指定内容名称、缩略图、描述与excel列的关联,导入时将取这些列的值保存为详情的相应字段。</span><br>
								</div>
								<fieldset style="padding:5px">
									<legend style="font-size:14px;font-weight:bold">excel设置</legend>
									<label style="margin-left:10px">excel文件:</label><span id="uploadArea"><s:file name="fileInput" cssClass="uploadarea"></s:file></span><br>
									<label style="margin-left:10px">要导入的sheet:</label><s:textfield name="sheetNo" cssClass="uploadarea" /><span>数字,默认为:第一个sheet</span><br>
									<label style="margin-left:10px">表头行数:</label><s:textfield name="headRow" cssClass="uploadarea" /><span>数字</span><br>
								</fieldset>
								<fieldset style="padding:5px">
									<legend style="font-size:14px;font-weight:bold">excel表头的字段关联</legend>
									<label style="margin-left:10px">用户唯一标志:</label><s:textfield name="excelImpAttrMapping.uniqueUserAttr" cssClass="uploadarea" /><span>如:用户名</span><br>
									<label style="margin-left:10px">用户登录密码:</label><s:textfield name="excelImpAttrMapping.password" cssClass="uploadarea" /><span>如:登录密码</span><br>
									<label style="margin-left:10px">内容名称:</label><s:textfield name="excelImpAttrMapping.title" cssClass="uploadarea" /><br>
									<label style="margin-left:10px">内容描述:</label><s:textfield name="excelImpAttrMapping.description" cssClass="uploadarea" /><br>
									<label style="margin-left:10px">内容缩略图:</label><s:textfield name="excelImpAttrMapping.thumb" cssClass="uploadarea" /><br>
								</fieldset>
							</s:form>
							<input style="position: relative;left: 43%;margin: 10px;" id="excelImpBtn" type="button" value="导入" onclick="excelImp()"><br>
							<span id="infoShow" style="color:red;margin-left:20px;"></span>
							</div>
						</div>
						<!-- <a class="btn_addnew" href="javascript:openDialog()">添加已有详情</a> -->
						<br>
					</div>


					<table class="fullwidth" cellpadding="0" cellspacing="0" border="0">
						<thead>
							<tr>
								<td>
									图片
								</td>
								<td>
									内容名称
								</td>
								<td>
									内容描述
								</td>
								<td>
									发布时间
								</td>
								<td>
									更新时间
								</td>
								<td>
									点击次数
								</td>
								<s:if test="catelogTab!=null">
								  <td>预订单数</td>
								</s:if>
								<td>
								</td>
								<td>
									<span>操作<img alt="刷新" onclick="refreshData(<s:property value="intCateId"/>);" title="刷新数据和顺序" style="width:16px;height:16px;margin-left:8px;vertical-align:bottom;" src="<%=path%>/images/refresh.png" /></span>
								</td>
							</tr>
						</thead>
						<tbody>
							<s:iterator value="appContentList">
								<tr class="odd">
									<td>
										<img alt="" src="<s:property value="varContentImgUrl" />"
											width="76" height="53">
									</td>

									<td>
										<s:if test="varContentName.length()>20">
											<s:property value="varContentName.substring(0,10)" />...
										</s:if>
										<s:else>
											<s:property value="varContentName" />
										</s:else>
									</td>
									<td>
										<s:if test="varContentDescript.length()>20">
											<s:property value="varContentDescript.substring(0,10)" />...
										</s:if>
										<s:else>
											<s:property value="varContentDescript" />
										</s:else>
									</td>
									<td>
										<s:property value="datAddDatetime" />
									</td>
									<td>
										<s:property value="datUpdateDatetime" />
									</td>
									<td>
										<s:property value="intViewCount" />
									</td>
									<s:if test="sysCateId==0">
									   <td>
									      <s:if test="intEcOrderCount!=0">
									        <a href="<%=path%>/userActions/getOrderListInit.action?targetId=<s:property value="intContentId+480000000000l"/>"><s:property value="intEcOrderCount"/>
									        </a>
									      </s:if>
									      <s:else>
									       	<s:property value="intEcOrderCount"/>
									      </s:else>
									   </td>
									</s:if>	
									<s:else>
									   <td>
									   </td>
									</s:else>								
									<s:if test="sysCateId==3">
										<td>
											<a href="javascript:getEnterShop('<s:property value="intContentId"/>')">地域列表</a>
										</td>
									</s:if>
									<s:else>
										<td>
										</td>
									</s:else>
									<td>
										<a class="icon icon_edit" title="编辑" onclick="showLoadStatus();"
											href="<%=path%>/dataBinding/goEditContent.action?intContentId=<s:property value="intContentId"/>&intCateId=<s:property value="intCateId"/>"></a>

										<a class="icon icon_detail" title="详细" href="javascript:"
											onclick="window.open('<%=path%>/dataBinding/goContentDetail.action?intContentId=<s:property value="intContentId"/>','详情信息','location=no,menubar=no,scrollbars=yes,resizable=yes,width=900px,top=0px,left=100px');"></a>
										<a class="icon icon_delete" title="删除 "
											href="javascript:delContentDetail('<s:property value="intContentId" />','<s:property value="intCateId"/>')"></a>
											
										<script type="text/javascript">
											function doDataTop(intContentId,intCateId){
												$.ajax({
													url : root+'/dataBinding/doDataTop.action?intContentId='+intContentId+'&intCateId='+intCateId,
													method : 'post',
													dataType : 'json',
													success : function(data) {
														if(data==null){
															$("#topOpr"+intContentId).html("取消置顶");
															$("#topOpr"+intContentId).attr("href","javascript:doCancelDataTop("+intContentId+","+intCateId+")");
														}
													},
													error:function(err){
														if(err.responseText!='')
															alert(err.responseText);
														else
															alert("请求失败！");
													}
												});
											}
											
											function doCancelDataTop(intContentId,intCateId) {
												$.ajax({
													url : root+'/dataBinding/doCancelDataTop.action?intContentId='+intContentId,
													method : 'post',
													dataType : 'json',
													success : function(data) {
														if(data==null){
															$("#topOpr"+intContentId).html("置顶");
															$("#topOpr"+intContentId).attr("href","javascript:doDataTop("+intContentId+","+intCateId+")");
														}
													},
													error:function(err){
														if(err.responseText!='')
															alert(err.responseText);
														else
															alert("请求失败！");
													}
												});
											}
										</script>
										
										<s:if test="intSortOrder>0">
											<a id="topOpr<s:property value='intContentId'/>" style="text-decoration: none;margin:5px;white-space: nowrap;" 
												href="javascript:doCancelDataTop(<s:property value="intContentId"/>,<s:property value="intCateId"/>)">取消置顶</a>
										</s:if>
										<s:else>
											<a id="topOpr<s:property value='intContentId'/>" style="text-decoration: none;margin:5px;white-space: nowrap;" 
												href="javascript:doDataTop(<s:property value="intContentId"/>,<s:property value="intCateId"/>)">置顶</a>
										</s:else>
									</td>

								</tr>
							</s:iterator>
						</tbody>
					</table>
				</div>
				<!-- 分页标签开始 -->
				<div align="right" style="float: right;">
					<d:page id="pageContent" template="details" skin="gray">
					</d:page>

				</div>
			</div>
			<!-- 分页标签结束 -->

		</div>


		<!-- 新增已有详情的弹出层 -->
		<div id="addContentDialog" style="display: none;">
			<s:form action="/dataBinding/doCopyContent.action" method="post"
				name="copyContetnForm" id="copyContetnForm">
				<s:hidden name="intCateId" id="intCateId"></s:hidden>
				<s:hidden name="contengCks" id="contengCks"></s:hidden>
				<TABLE border=0 height=600px align=left>
					<TR>
						<TD class="left" style="margin-top: 10px" valign=top>
							<ul id="tree" class="ztree" style="overflow: auto;"></ul>
						</TD>
						<TD width=100% align=left valign=top
							style="background: url(../body_radio.gif) 0 0 no-repeat;">
							<IFRAME ID="content" Name="content" FRAMEBORDER=0 SCROLLING=no
								width=100% height=600px SRC=""></IFRAME>
						</TD>
					</TR>
				</TABLE>
			</s:form>
		</div>
	</body>
</html>
